//
//  CZFooterView.swift
//  sinaSwifWeiBo
//
//  Created by 张雪雪 on 16/3/5.
//  Copyright © 2016年 张雪雪. All rights reserved.
//

import UIKit

class CZFooterView: UIView {

    //定义一个viewModel(需要传值  展示评论或者转发的属性,没有转发或者评论数量的时候,只显示文字)
    var footerViewModel : CZStatusViewModel?{
    
    
        didSet{
        
        //显示转发数据
//            评论数据
            //点赞的数量
            retweetButton.setTitle(footerViewModel?.retweetString, forState: UIControlState.Normal)
            commentsButton.setTitle(footerViewModel?.commentString, forState: UIControlState.Normal)
            goodButton.setTitle(footerViewModel?.attitudesString, forState: UIControlState.Normal)
        }

    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    //防止崩溃
     required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //添加控件和约束
    private func setupUI(){
        backgroundColor = UIColor.greenColor()
        
        addSubview(retweetButton)
        addSubview(commentsButton)
        addSubview(goodButton)
        
        let lineLeft = getLine()
        let lineRight = getLine()
        
        addSubview(lineLeft)
        addSubview(lineRight)
    
        //添加约束
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
        
            //关键的约束宽度
            make.width.equalTo(commentsButton.snp_width)
        }
    
    //评论按钮
        commentsButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetButton.snp_right)
            make.top.equalTo(self.snp_top)
            make.right.equalTo(goodButton.snp_left)
            make.bottom.equalTo(self.snp_bottom)
        }
        
    goodButton.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(self.snp_top)
        make.right.equalTo(self.snp_right)
        make.bottom.equalTo(self.snp_bottom)
        //宽度
        make.width.equalTo(commentsButton.snp_width)
        }
        
        lineLeft.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            
        }
        
        lineRight.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentsButton.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            
        }
        
        
    
    }
    
    //懒加载
    
    private lazy var retweetButton: UIButton = {
    
    let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "timeline_icon_retweet"), forState: UIControlState.Normal)
        button.setTitle("转发", forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor(white: 0.95, alpha: 1), forState: UIControlState.Normal)
       
        
    
       return button
    }()
    
    //评论按钮
    private lazy var commentsButton:UIButton = {
    
    let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "timeline_icon_comment"), forState: UIControlState.Normal)
        button.setTitle("评论", forState: UIControlState.Normal)
        button.setTitleColor(UIColor(white: 0.95, alpha: 1), forState: UIControlState.Normal)
        return button
    }()
    //创建点赞按钮
    private lazy var goodButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "timeline_icon_like"), forState: UIControlState.Normal)
        button.setTitle("赞", forState: UIControlState.Normal)
        button.setTitleColor(UIColor(white: 0.95, alpha: 1), forState: UIControlState.Normal)
    
        return button
    }()
    //创建一个方法,返回一个UIImageView 线
    private func getLine() -> UIImageView{
    
    let imageView = UIImageView()
        
        imageView.image = UIImage(named: "timeline_card_bottom_line_highlighted")
        
        return imageView
    
    }
    
    
}
